<template>
    <div class="l-from-body" >
        <el-form :model="formData" :rules="rules" size="mini"  ref="form" label-width="150px" >
            <el-col :span="24">
                <el-form-item :label="$t('条件名称')" prop="name">
                    <el-input  v-model="formData.name" >
                    </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item :label="$t('数据库')" prop="dbCode">
                    <el-select v-model="formData.dbCode" :placeholder="$t('请选择')">
                        <el-option-group
                        v-for="group in lr_dblinkTree"
                        :key="group.id"
                        :label="group.label">
                        <el-option
                            v-for="item in group.children"
                            :key="item.id"
                            :label="item.label"
                            :value="item.id">
                        </el-option>
                        </el-option-group>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item :label="$t('数据表')" prop="table">
                    <l-codetable-select
                    @change="handleTableChange"
                    :dbCode="formData.dbCode" 
                    v-model="formData.table"></l-codetable-select>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item :label="$t('关联流程字段')" prop="rfield">
                    <l-select :options="formData.columns" valueKey="name" labelKey="coment" v-model="formData.rfield" >
                    </l-select>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item :label="$t('比较字段')" prop="cfield">
                    <l-select :options="formData.columns"  valueKey="name" labelKey="coment" v-model="formData.cfield" >
                    </l-select>
                </el-form-item>
            </el-col>
           <el-col :span="24">
                <el-form-item :label="$t('比较类型')" prop="compareType">
                    <l-select :options="options"  v-model="formData.compareType" >
                    </l-select>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item :label="$t('数据值')" prop="value">
                    <el-input  v-model="formData.value" >
                    </el-input>
                </el-form-item>
            </el-col>
        </el-form>
    </div>
</template>
<script>
export default {
    name:'condition-formula',
    props:{
    },
    data(){
        return {
            formData:{
                dbCode:'',
                table:'',
                columns:[],
                rfield:'',
                cfield:'',
                compareType:'',
                value:'',
                name:''
            },
            rules: {
                dbCode: [
                    { required: true, message: this.$t('请选择数据库') }
                ],
                table: [
                    { required: true, message: this.$t('请选择数据表') }
                ],
                rfield: [
                    { required: true, message: this.$t('请选择关联字段') }
                ],
                cfield: [
                    { required: true, message: this.$t('请选择比较字段') }
                ],
                compareType: [
                    { required: true, message: this.$t('请选择比较类型') }
                ],
                value: [
                    { required: true, message: this.$t('请填写值') }
                ],
                name: [
                    { required: true, message: this.$t('请填写条件名称') }
                ]
            },
            options:[
                { value: '1', label: this.$t('等于') }, 
                { value: '2', label: this.$t('不等于') },
                { value: '3', label: this.$t('大于') }, 
                { value: '4', label: this.$t('大于等于') }, 
                { value: '5', label: this.$t('小于') }, 
                { value: '6', label: this.$t('小于等于') }, 
                { value: '7', label: this.$t('包含') }, 
                { value: '8', label: this.$t('不包含') }, 
                { value: '9', label: this.$t('包含于') },
                { value: '10', label: this.$t('不包含于') }]
        };
    },
    computed:{
    },
    created () {
    },
    methods:{
        handleTableChange(table){
            this.formData.columns = table.columns;
        },
        resetForm(){
            this.formData.columns = [];
            this.$refs.form && this.$refs.form.resetFields();
        },
        // 校验表单
        validateForm(callback){
            this.$refs.form.validate((valid) => {
                if(valid){
                    callback();
                }
            });
        },
        setForm(data){
            this.formData = this.$deepClone(data);
        },
        getForm(){
            let formData = this.$deepClone(this.formData);
            return formData;
        }
    }
}
</script>